package com.news.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.news.entity.News;
import com.news.service.NewsService;


@WebServlet("/adminnewsedit")
public class AdminNewsEditServlet extends HttpServlet {

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		HttpSession session=request.getSession();
		String title = request.getParameter("title");
		String content = request.getParameter("content");
		String image_url = request.getParameter("photo");
		String news_type = request.getParameter("news_type");
		int user_id = (int) session.getAttribute("user_id");
		int id = (int) session.getAttribute("id");
		News news = new News();
		news.setTitle(title);
		news.setContent(content);
		news.setImage_url(image_url);
		news.setNews_type(news_type);
		news.setUser_id(user_id);
		news.setId(id);
		
		NewsService newsService = new NewsService();
		boolean flag = newsService.editNews(news);
		if (flag) {
			response.sendRedirect(request.getContextPath()+"/adminnewslist");
		}
	}

}
